
public class Rabbit {


    public static void main(String[] args) {
        final int MONTH = 12;
        Rabbit rabbit = new Rabbit();
        int num = rabbit.rabbitNum(MONTH);
        //System.out.println("after "+ MONTH+ " month later,the rabbit number is " + num);
        System.out.println(MONTH + " ---> " + num);
    }

    /**
     * Rabbit all number
     * @param month
     * @return
     */
    public int rabbitNum(int month) {
        return rabbitAdultNum(month) + rabbitMinorsOneNum(month) + rabbitMinorsTwoNum(month);
    }

    /**
     * Adult Rabbit number
     * @param month
     * @return
     */
    public int rabbitAdultNum(int month) {
        if (month < 0) {
            return 0;
        }
        if (month == 1 || month == 2) {
            return 0;
        }
        if (month == 3) {
            return 2;
        }
        return rabbitAdultNum(month -1) + rabbitMinorsTwoNum(month-1);
    }

    /**
     * One month old,Minors rabbit number
     * @param month
     * @return
     */
    public int rabbitMinorsOneNum(int month) {
        if (month < 0) {
            return 0;
        }
        if (month == 1) {
            return 2;
        }
        if (month == 2) {
            return 0;
        }
        return rabbitAdultNum(month);
    }

    /**
     * Two month old,Minors rabbit number
     * @param month
     * @return
     */
    public int rabbitMinorsTwoNum(int month) {
        if (month < 0) {
            return 0;
        }
        if (month == 1 || month == 3) {
            return 0;
        }
        if (month == 2) {
            return 2;
        }

        return rabbitMinorsOneNum(month-1);
    }
}
